/*
 * Copyright 2009 Original Author(s)
 * 
 * This file is part of Kommando
 * 
 * Kommando is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Kommando is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Kommando.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.kommando.shelf;

import java.awt.Dimension;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;

import org.kommando.ui.DisplayableListCellRenderer;
import org.kommando.ui.support.PrototypeDisplayable;

import ca.odell.glazedlists.swing.EventListModel;

/**
 * @author Peter De Bruycker
 */
public class ShelfDialog {

    private JDialog dialog;
    private Shelf shelf;

    public ShelfDialog(Shelf shelf) {
        this.shelf = shelf;

        dialog = new JDialog((JFrame) null, "Shelf");
        JList list = new JList();
        ListModel model = new EventListModel<ShelfEntry>(shelf.getEntries());
        list.setModel(model);
        list.setCellRenderer(new DisplayableListCellRenderer(new Dimension(32, 32)));
        list.setVisibleRowCount(10);
        list.setPrototypeCellValue(new PrototypeDisplayable());
        list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        dialog.add(new JScrollPane(list));
        dialog.setAlwaysOnTop(true);
        dialog.pack();
    }

    public void show() {
        dialog.setVisible(true);
    }

    public void hide() {
        dialog.setVisible(false);
    }

}
